#ifndef _RTSESSION_H_
#define _RTSESSION_H_

#include "RtGlobal.h"

#include <QObject>
#include <QScriptValue>
#include <QScriptProgram.h>

class QScriptEngine;
class QScriptContext;
class QTimer;

class RTLAB_BASE_EXPORT RtScriptEngine : public QObject
{
protected:
	QScriptEngine* engine_;

public:
	RtScriptEngine(QObject* parent);

	QScriptEngine* getEngine() const { return engine_; }

	bool canEvaluate(const QString&);
	bool isEvaluating() const;
	bool evaluate(const QScriptProgram& program, QString& ret);
	bool evaluate(const QString& program, QString &ret);
	void abortEvaluation();
};

class RTLAB_BASE_EXPORT RtSession : public RtScriptEngine
{
	Q_OBJECT

protected:
	QTimer* wait_timer_;
	bool wait_aborted_;

public:
    RtSession(QObject* parent = 0);
	virtual ~RtSession(void);
    void evaluate(const QString& program);
    void abortEvaluation();

public slots:
    void quit();
    void exec(const QString& fname);
    void print(const QString& str);
    void wait(uint ms);
    void textSave(const QString& str, const QString& fname);
    QString textLoad(const QString& fname);

signals:
	void stdOut(const QString&);
	void stdErr(const QString&);
	void endSession();
};

#endif


